package com.eip.zd.controller;

import com.eip.zd.common.Result;
import com.eip.zd.entity.Prod;
import com.eip.zd.service.ProdService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/prod")
public class ProdController {
    @Resource
    private ProdService prodService;

    @GetMapping("/getProdList")
    public Result getProdList(@RequestParam(required = false) String keyword) {
        List<Prod> prodList = prodService.getProdList(keyword);
        return Result.success(prodList);
    }
    @GetMapping("/getCustProdList/{custId}")
    public Result getCustProdList(@PathVariable String custId, @RequestParam(required = false) String keyword) {
        List<Prod> prodList = prodService.getCustProdList(custId, keyword);
        return Result.success(prodList);
    }
    @GetMapping("/getTenProd")
    public Result getTenProd(@RequestParam(required = false) String keyword) {
        List<Prod> prodList = prodService.getTenProd(keyword);
        return Result.success(prodList);
    }
    @PostMapping("/add")
    public Result addProd(@RequestBody Prod prod) {
        prodService.add(prod);
        return Result.success();
    }
    @PostMapping("/update")
    public Result updateProd(@RequestBody Prod prod) {
        prodService.update(prod);
        return Result.success();
    }
    @PostMapping("/remove/{id}")
    public Result removeProd(@PathVariable Long id) {
        prodService.remove(id);
        return Result.success();
    }
    @PostMapping("/ifUse/{id}")
    public Result ifUse(@PathVariable Long id) {
        prodService.ifUse(id);
        return Result.success();
    }
}
